class Reservation < ApplicationRecord
  belongs_to :restaurant

  scope :filter_date, ->(date) { where date: date if date.present?}
  scope :filter_time, ->(start_time, end_time) {
    if start_time.present? && end_time.present?
      start_time, end_time = start_time.to_i, end_time.to_i
      where '`start_time` < ? and `end_time` > ?', end_time, start_time
    end
  }
end
